﻿namespace DesignModeConsole.行为型.中介者模式.基础;

/// <summary>
/// 抽象同事角色
/// </summary>
public abstract class Colleague
{
    /// <summary>
    /// 声明中介者对象，用于与其他同事类交互
    /// </summary>
    protected Mediator1 _mediator1;

    public Colleague(Mediator1 mediator1)
    {
        _mediator1 = mediator1;
    }

    /// <summary>
    /// 发送消息
    /// </summary>
    /// <param name="message"></param>
    public abstract void Publish(string message);

    /// <summary>
    /// 接收消息
    /// </summary>
    /// <param name="message"></param>
    public abstract void ReceiveMessage(string message);
}

/// <summary>
/// 具体的同事类a
/// </summary>
public class ColleagueA : Colleague
{
    public ColleagueA(Mediator1 mediator) : base(mediator)
    {
    }

    public override void Publish(string message)
    {
        Console.WriteLine($"A发送消息{message}");
        _mediator1.Send(message, this);
    }

    public override void ReceiveMessage(string message)
    {
        Console.WriteLine($"A接收到消息{message}");
    }
}

/// <summary>
/// 具体同事类b
/// </summary>
public class ColleagueB : Colleague
{
    public ColleagueB(Mediator1 mediator) : base(mediator)
    {
    }

    public override void Publish(string message)
    {
        Console.WriteLine($"B发送消息{message}");
        _mediator1.Send(message, this);
    }

    public override void ReceiveMessage(string message)
    {
        Console.WriteLine($"B接收到消息{message}");
    }
}